package com.example.springboot.controller;


import com.example.springboot.pojo.Repair;
import com.example.springboot.pojo.Result;
import com.example.springboot.service.FileService;
import com.example.springboot.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/repair")
public class RepairController {

    @Autowired
    private RepairService repairService;
    @Autowired
    private FileService fileService;
//    @GetMapping
//    public Repair findById(Integer id){
//
//    }
//    private Repair repair = new Repair();
//
//    @PostMapping("/uploadPhoto")
//    public Result<?> uploadPhoto(MultipartFile file) throws IOException {
//        String url = fileService.uploadFile(file);
////        homeService.uploadImg(url);
//        repair.setPhoto(url);
//        return Result.success("上传成功");
//    }

    @PostMapping("/addRepair")
    public Result<?> addRepair(String roomNumber, String detail,String photo){
//        String photo = fileService.uploadFile(file);
//        System.out.println("url:" + photo);
        repairService.addRepair(roomNumber,detail,photo);
        return Result.success();
    }

    @GetMapping("/getAllRepair")
    public Result<?> getAllRepair(){
        Repair[] repairList = repairService.getAllRepair();
        return Result.success(repairList);
    }

    @GetMapping("/getByRoomNumber")
    public Result<?> getByRoomNumber(String roomNumber){
        Repair[] repairList = repairService.getByRoomNumber(roomNumber);
        return Result.success(repairList);
    }

    @GetMapping("/getByWorkerId")
    public Result<?> getByWorkerId(String workerId){
//        System.out.println(workerId);
        Repair[] repairList = repairService.getByWorkerId(workerId);
        return Result.success(repairList);
    }

    @PutMapping("/deleteRepair")
    public Result<?> deleteRepair(Integer id){
        repairService.deleteRepair(id);
        return Result.success();
    }

    @PutMapping("/passRepair")
    public Result<?> passRepair(Integer id,String workerId){
        repairService.passRepair(id,workerId);
        return Result.success();
    }

    @PutMapping("/finishRepair")
    public Result<?> finishRepair(Integer id){
        repairService.finishRepair(id);
        return Result.success();
    }
}
